@extends('admin.admin')

@section('content')
  <link rel="stylesheet" href="/components/AdminLTE/plugins/daterangepicker/daterangepicker-bs3.css">

  <!-- date-range-picker -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.10.2/moment.min.js"></script>
  <script src="/components/AdminLTE//plugins/daterangepicker/daterangepicker.js"></script>
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      订单管理
      <small>推送订单列表</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="/admin"><i class="fa fa-dashboard"></i> 控制面板</a></li>
      <li ><a href="/admin/order">订单管理</a></li>
      <li class="active">推送订单列表</li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">

    <div class="row">
      <div class="col-xs-12">

        <div class="box box-primary ">
          <div class="box-body table-responsive">

            {!! Form::model(@$orderInfo,array('route' => 'admin.push_tarrif.index','method' => 'get','class'=>'form-search form-inline')) !!}
            <div class="form-group">
              {!! Form::text('order_sn',@$_GET['order_sn'],array('class'=>'form-control ','placeholder'=>'订单号'))!!}
            </div>
            <div class="form-group">
              {!! Form::select('push_tarrif_status',[
              '0'=>'所有状态',
              '1'=>'待推关',
              '2'=>'已推关',
              '3'=>'已取消',
              '4'=>'推关失败',
              ],$filter['push_tarrif_status'],['class'=>'form-control','placeholder'=>'推关状态'])!!}
            </div>

            <div class="form-group">
              <button type="submit" class="btn btn-primary " ><i class="fa  fa-filter"></i>筛选</button>
              <a href="/admin/push_tarrif?order_sn=&push_tarrif_status=0" class="btn btn-default">重置</a>
            </div>
            {!! Form::close() !!}
          </div>

        </div><!-- end .box box-primary -->

        <div class="box box-primary">

          <div class="box-header">
            <h3 class="box-title">订单列表</h3>

          </div>
          <!-- /.box-header -->
          <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
              <tr>
                <th class="col-sm-1" style=''>ID</th>
                <th class="col-sm-1" style=''>订单id</th>
                <th class="col-sm-1" style='text-align: center;'>订单编号</th>
                <th class="col-sm-1" style='text-align: center;'>推关状态</th>
                {{--<th class="col-sm-1 J-instatus" style='text-align: center;'>入关业务单据状态</th>--}}
                {{--<th class="col-sm-1 J-indistStatus" style='text-align: center;'>出关业务单据状态</th>--}}
                {{--<th class="col-sm-1 J-outstatus" style='text-align: center;'>入关核放单据状态</th>--}}
                {{--<th class="col-sm-1 J-outdistStatus" style='text-align: center;'>出关核放单据状态</th>--}}
                <th class="col-sm-1" style='text-align: center;'>失败原因</th>
                <th class="col-sm-1" style='text-align: center;'>可推关的开始时间</th>
                <th class="col-sm-1" style='text-align: center;'>操作</th>
              </tr>
              @foreach ($orderInfo as $order)
                <tr>
                  <td class="col-sm-1" style=''>{{$order->id}}</td>
                  <td class="J-orderId col-sm-1" data-id="{{$order->order_id}}" style=''>{{$order->order_id}}</td>
                  <td class="col-sm-2" style='text-align: center;'>{{$order->order_sn}}</td>
                  <td class="col-sm-1" style='text-align: center;'>
                    <?php
                    switch($order->push_tarrif_status){
                      case 1:
                        echo '待推关';
                        break;
                      case 2:
                        echo '已推关';
                        break;
                      case 3:
                        echo '已取消';
                        break;
                      case 4:
                        echo '推关失败';
                        break;
                    }
                    ?>
                  </td>
                  {{--<td class="J-instatus" style='text-align: center;'></td>--}}
                  {{--<td class="J-indistStatus" style='text-align: center;'></td>--}}
                  {{--<td class="J-outstatus" style='text-align: center;'></td>--}}
                  {{--<td class="J-outdistStatus" style='text-align: center;'></td>--}}
                  <td style='text-align: center;'>{{$order->reasion}}</td>
                  <td style='text-align: center;'>{{$order->add_time}}</td>
                  <td style='text-align: center;'>
                    <a href="/admin/order/{{$order->order_id}}?back_url=<?php echo urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);?>" type="button" class="btn btn-default btn-xs">
                      <i class="glyphicon glyphicon-eye-open"></i>&nbsp;订单详情
                    </a>

                  @if(@$order->push_tarrif_status==1 || $order->push_tarrif_status==4)
                    <a type="button" class="btn btn-success btn-xs" data-toggle="modal" data-target="#myModal1" style="margin-top: -4px;margin-left: 10px;" href="javascript:void(0);" onclick="$('#order_id').val({{$order->order_id}})">
                      <i class="fa fa-credit-card"></i> 推送海关
                    </a>
                  @endif

                  @if(@$order->push_tarrif_status==2)
                    <a type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal1" style="margin-top: -4px;margin-left: 10px;" href="javascript:void(0);" onclick="$('#order_id').val({{$order->order_id}})">
                      <i class="fa fa-credit-card"></i> 再次推送
                    </a>
                  @endif


                  @if(@$order->push_tarrif_status==1)
                    <a type="button" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal2" style="margin-top: -4px;margin-left: 10px;" href="javascript:void(0);" onclick="$('#order_id2').val({{$order->order_id}})">
                      <i class="fa fa-credit-card"></i> 取消推送
                    </a>
                  @endif
                  </td>
                </tr>
              @endforeach

            </table>
          </div>
          <!-- /.box-body -->

          <div class="box-footer">
            <!-- 分页 -->
            <div class="pull-right no-margin-pager">
              {!! $orderInfo->appends($filter)->render() !!}
            </div>

            {{--<a href="{{$downloadUrl}}" type="submit" class="btn btn-default pull-right-" ><i class="fa  fa-download"></i>&nbsp;导出</a>--}}

          </div>
        </div>
        <!-- /.box -->
      </div>
    </div>
    </div>


  </section>

<!-- Modal -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">推关</h4>
      </div>
      <div class="modal-body">
        <div class="row">
            <div class="col-xs-12">
              确认推送至海关吗?
            </div>
            <input type="hidden" id="order_id" value="" />
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button id="pushBtn" type="button" class="btn btn-primary">点击推送</button>
        <button id="pushBtnOld" type="button" class="btn btn-primary">旧版推送</button>
      </div>
    </div>
  </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">取消推关</h4>
      </div>
      <div class="modal-body">
        <div class="row">
            <div class="col-xs-12">
              确认取消海关推送吗?
            </div>
            <input type="hidden" id="order_id2" value="" />
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
        <button id="cancelPushBtn" type="button" class="btn btn-primary">确定</button>
      </div>
    </div>
  </div>
</div>
  <script>
    var daterRange=$('#daterange-btn'),input=$('#time'),getTime=input.val();

    utils.datePredefinedRanges(daterRange,input,getTime);
  </script>

  <script type="text/javascript">


        {{--var order_id = $(".J-orderId");--}}

        {{--order_id.each(function(){--}}
            {{--var that=$(this),id=that.data('id');--}}
            {{--var tr = that.closest('tr');--}}
                    {{--$.ajax({--}}
                       {{--url:'/admin/push_tarrif/get_status',--}}
                       {{--type:'get',--}}
                       {{--dataType:'json',--}}
                       {{--data: {order_id: id, '_token': '{{csrf_token()}}'},--}}
                       {{--success:function(res){--}}
                            {{--console.log(res.order.in.status);--}}
                            {{--if($.isEmptyObject(res.order.in.status)){--}}
                                {{--tr.find('.J-instatus').text('无');--}}
                            {{--}else{--}}
                                {{--tr.find('.J-instatus').text(res.order.in.status);--}}
                            {{--}--}}
                            {{--if($.isEmptyObject(res.order.in.distStatus)){--}}
                                {{--tr.find('.J-indistStatus').text('无');--}}
                            {{--}else{--}}
                                {{--tr.find('.J-indistStatus').text(res.order.in.distStatus);--}}
                            {{--}--}}
                            {{--if($.isEmptyObject(res.order.out.status)){--}}
                                {{--tr.find('.J-outstatus').text('无');--}}
                            {{--}else{--}}
                                {{--tr.find('.J-outstatus').text(res.order.out.status);--}}
                            {{--}--}}
                            {{--if($.isEmptyObject(res.order.out.distStatus)){--}}
                                {{--tr.find('.J-outdistStatus').text('无');--}}
                            {{--}else{--}}
                                {{--tr.find('.J-outdistStatus').text(res.order.out.distStatus);--}}
                            {{--}--}}
{{--//                            !$.isEmptyObject(res.order.in.status)&&tr.find('.J-instatus').text(res.order.in.status);--}}
{{--//                            !$.isEmptyObject(res.order.in.distStatus)&&tr.find('.J-indistStatus').text(res.order.in.distStatus);--}}
{{--//                            !$.isEmptyObject(res.order.out.status)&&tr.find('.J-outstatus').text(res.order.out.status);--}}
{{--//                            !$.isEmptyObject(res.order.out.distStatus)&&tr.find('.J-outdistStatus').text(res.order.out.distStatus);--}}

                       {{--}--}}
                    {{--});--}}
        {{--});--}}



  $('#pushBtn').click(function(e){

    var btn = $(this);
    var order_id = $("#order_id").val();


    btn.attr('正在推送..');

    btn.addClass('disabled');

    $.ajax({
      url:'/admin/order/push/'+order_id,
      type:'post',
      dataType:'json',
      success:function(res){

        btn.removeClass('disabled');
        btn.val('点击推送');


        if (res.status=='success'){

          window.location.reload();
        }else{
          alert(res.message);
        }

      },
      error:function(){
        btn.removeClass('disabled');
        btn.val('点击推送');
      }

    });


  });

  $('#pushBtnOld').click(function(e){

    var btn = $(this);
    var order_id = $("#order_id").val();


    btn.attr('正在推送..');

    btn.addClass('disabled');

    $.ajax({
      url:'/admin/order/push_old/'+order_id,
      type:'post',
      dataType:'json',
      success:function(res){

        btn.removeClass('disabled');
        btn.val('点击推送');


        if (res.status=='success'){

          window.location.reload();
        }else{
          alert(res.message);
        }

      },
      error:function(){
        btn.removeClass('disabled');
        btn.val('点击推送');
      }

    });


  });


  $('#cancelPushBtn').click(function(e){

    var btn = $(this);
    var order_id = $("#order_id2").val();


    btn.attr('正在取消..');

    btn.addClass('disabled');

    $.ajax({
      url:'/admin/push_tarrif/'+order_id,
      type:'PUT',
      dataType:'json',
      success:function(res){

        btn.removeClass('disabled');
        btn.val('点击推送');


        if (res.status=='success'){

          window.location.reload();
        }else{
          alert(res.message);
        }

      },
      error:function(){
        btn.removeClass('disabled');
        btn.val('点击取消');
      }

    });


  });
  </script>
  <!-- /.content -->
@endsection